package 力扣日常刷题.木22二月.第01天206;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 帅小伙
 * @date 2022/2/6
 * @description
 */
public class Demo18最长不含重复字符的子字符串 {

    public int lengthOfLongestSubstring(String s) {

        Map<Character,Integer> map = new HashMap<Character,Integer>();
        int res = 0,i = -1;
        for (int j = 0; j < s.length(); j++) {
            if(map.containsKey(s.charAt(j)))
                i = Math.max(i,map.get(s.charAt(j)));
            map.put(s.charAt(j),j);
            res = Math.max(res,j - i);
        }
        return res;

    }
}
